import csv
import json
from time import sleep

import ddt
import unittest
import yaml
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class TestJDLogin(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Chrome()
        cls.driver.maximize_window()

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    def test_login(self):

        self.driver.get("https://www.jd.com")
        wait = WebDriverWait(self.driver, 10)
        sleep(11)
            # 点击登录链接
            # wait.until(EC.presence_of_element_located((By.LINK_TEXT, "你好，请登录"))).click()
            # sleep(5)
            # # 输入用户名和密码
            # self.driver.find_element(By.ID, "loginname").send_keys(data['username'])
            # self.driver.find_element(By.ID, "nloginpwd").send_keys(data['password'])
            # sleep(5)
            # self.driver.find_element(By.ID, "loginsubmit").click()
            # sleep(5)
            # # 检查页面标题
            # self.assertEqual(data['expected_title'], self.driver.title)

            # 检查错误信息
            # error_element = wait.until(EC.presence_of_element_located((By.ID, "msg")))
            # self.assertIn(data['error_msg'], error_element.text)
            #
            # # 清空输入框
            # self.driver.find_element(By.ID, "loginname").clear()
            # self.driver.find_element(By.ID, "nloginpwd").clear()

    # @ddt.file_data('data.csv')
    # @ddt.unpack
    # def test_login(self, username, password, expected_title, error_msg):
    #     self.driver.get("https://www.jd.com")
    #     wait = WebDriverWait(self.driver, 10)
    #
    #     # 点击登录链接
    #     wait.until(EC.presence_of_element_located((By.LINK_TEXT, "登录"))).click()
    #
    #     # 输入用户名和密码
    #     self.driver.find_element(By.ID, "loginname").send_keys(username)
    #     self.driver.find_element(By.ID, "nloginpwd").send_keys(password)
    #     self.driver.find_element(By.ID, "loginsubmit").click()
    #
    #     # 检查页面标题
    #     self.assertEqual(expected_title, self.driver.title)
    #
    #     # 检查错误信息
    #     error_element = wait.until(EC.presence_of_element_located((By.ID, "msg")))
    #     self.assertIn(error_msg, error_element.text)
    #
    #     # 清空输入框
    #     self.driver.find_element(By.ID, "loginname").clear()
    #     self.driver.find_element(By.ID, "nloginpwd").clear()



# def reverse_list(lst):
#     return lst[::-1]

if __name__ == "__main__":
    unittest.main()
#
#     print(reverse_list([42, 63, 457, 26, 57, 82, 65, 876, 2, 856]))